/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controladores;

import entidades.Area;
import entidades.Facultad;
import entidades.Programa;
import java.util.List;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author BATAQUERO
 */
@Stateless
public class AreaFacade extends AbstractFacade<Area> implements AreaFacadeLocal {
    @PersistenceContext(unitName = "KonbitacoraPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AreaFacade() {
        super(Area.class);
    }

    @Override
    public List<Area> listaAreasXPrograma(Programa idPrograma) {
        try {
            System.out.println("entra al metodo lista de ares en areafacade ");
            Query q = em.createNamedQuery("Area.findByIdPrograma");
            q.setParameter("idPrograma", idPrograma);
            List<Area> listaAreas = q.getResultList();
            //em.refresh(listaAreas);
            em.flush();
            return listaAreas;
        } catch (EJBException eJBException) {
            return null;
        } catch (NoResultException noResultException) {
            return null;
        }
    }

    @Override
    public List<Area> listaAreasXFacultad(Facultad idFacultad) {
        try {
            System.out.println("entra al metodo lista de ares en areafacade ");
            Query q = em.createNamedQuery("Area.findByIdFacultad");
            q.setParameter("idFacultad", idFacultad);
            List<Area> listaAreas = q.getResultList();
            //em.refresh(listaAreas);
            em.flush();
            return listaAreas;
        } catch (EJBException eJBException) {
            return null;
        } catch (NoResultException noResultException) {
            return null;
        }
    }
    
}
